package com.ourteam.product.ui.dao.impl;

import com.ourteam.product.ui.dao.IProductUIListDAO;
import com.ourteam.product.ui.dao.ProductUIList;
import com.ourteam.product.ui.dao.ProductUIListDAOQueryBean;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.jdbc.core.RowMapper;

/**
 * Template Name : DAO服务对象 Template Version : 1 Template Last Modfiy Date : Fri Nov 17 11:00:11 CST
 * 2017 Auto Generate Date : 2018-12-14 15:15:18 Warning ! This file will be overwrite when
 * regenerate !
 */
public class AbstractProductUIListDAOJdbcImpl extends AbstractSpringDAO
    implements IProductUIListDAO {

  public static final String[] ENTITY_FIELDS =
      new String[] {
        Id,
        DomainId,
        Code,
        Name,
        Type,
        ValueProperty,
        LabelProperty,
        LastModifyUser,
        LastModifyTime,
        Status,
        Remarks,
        IconProperty,
        Script,
        SearchProperty,
        DomainCode,
        DomainName
      };

  public static final String[] ENTITY_PROPERTIES =
      new String[] {
        _DataObjectProperty.Id,
        _DataObjectProperty.DomainId,
        _DataObjectProperty.Code,
        _DataObjectProperty.Name,
        _DataObjectProperty.Type,
        _DataObjectProperty.ValueProperty,
        _DataObjectProperty.LabelProperty,
        _DataObjectProperty.LastModifyUser,
        _DataObjectProperty.LastModifyTime,
        _DataObjectProperty.Status,
        _DataObjectProperty.Remarks,
        _DataObjectProperty.IconProperty,
        _DataObjectProperty.Script,
        _DataObjectProperty.SearchProperty,
        _DataObjectProperty.DomainCode,
        _DataObjectProperty.DomainName
      };

  public static final String[] ENTITY_PK_FIELDS = new String[] {Id};

  public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] {Id};

  public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {};

  private static String relatedJoinSQL = null;

  private static String basicFilterSQL = null;

  private DataAccessObjectHelper<ProductUIList, ProductUIListDAOQueryBean> daoHelper;

  public AbstractProductUIListDAOJdbcImpl() {
    super();
    daoHelper = new DataAccessObjectHelper<ProductUIList, ProductUIListDAOQueryBean>(this);
  }

  protected String getEntityName() {
    return EntityName;
  }

  protected String[] getEntityFields() {
    return ENTITY_FIELDS;
  }

  protected String[] getEntityProperties() {
    return ENTITY_PROPERTIES;
  }

  protected String[] getEntityPKFields() {
    return ENTITY_PK_FIELDS;
  }

  protected String[] getEntityAutoGenPKFields() {
    return ENTITY_AUTO_GEN_PK_FIELDS;
  }

  protected String[] getEntityUniqueFields() {
    return ENTITY_UNIQUE_FIELDS;
  }

  protected String getBaiscQueryFilter() {

    if (basicFilterSQL == null) {
      StringBuffer basicFilterSQLbuffer = new StringBuffer();

      basicFilterSQL = basicFilterSQLbuffer.toString();
    }

    return basicFilterSQL;
  }

  protected String getRelatedJoinSQL() {

    if (relatedJoinSQL == null) {
      StringBuffer relatedJoinSQLBuffer = new StringBuffer();

      relatedJoinSQLBuffer
          .append(" LEFT JOIN ")
          .append(com.ourteam.product.ui.dao.IProductUIDomainDAO.EntityName)
          .append(" PRODUCT_UI_DOMAIN ");

      relatedJoinSQLBuffer.append(" ON ( ");

      relatedJoinSQLBuffer.append(
          StringUtils.replace(
              com.ourteam.product.ui.dao.IProductUIDomainDAO.Id,
              com.ourteam.product.ui.dao.IProductUIDomainDAO.EntityName + ".",
              "PRODUCT_UI_DOMAIN."));
      relatedJoinSQLBuffer.append(" = ").append(DomainId);

      relatedJoinSQLBuffer.append(" ) ");

      relatedJoinSQL = relatedJoinSQLBuffer.toString();
    }

    return relatedJoinSQL;
  }

  /**
   * Check Data Unique
   *
   * @param aProductUIList
   * @throws Exception
   */
  public boolean checkIsUnique(ProductUIList aProductUIList) throws Exception {

    if (aProductUIList == null) {
      return true;
    }

    List valueList = new ArrayList();

    List pkValueList = new ArrayList();

    pkValueList.add(aProductUIList.getId());

    return isUnique(
        valueList.toArray(new Object[valueList.size()]),
        pkValueList.toArray(new Object[pkValueList.size()]));
  }

  /**
   * Insert Data
   *
   * @param aProductUIList
   * @throws Exception
   */
  public void insert(ProductUIList aProductUIList) throws Exception {

    PropertyUtils.setProperty(
        aProductUIList,
        _DataObjectProperty.LastModifyTime,
        new java.sql.Timestamp(System.currentTimeMillis()));

    super.doInsert(aProductUIList);
  }

  /**
   * Batch Insert Datas
   *
   * @param aProductUIList
   * @throws Exception
   */
  public void batchInsert(ProductUIList[] aProductUILists) throws Exception {

    super.doBatchInsert(aProductUILists);
  }

  /**
   * Delete Data
   *
   * @param final long id *
   * @throws Exception
   */
  public void delete(final long id) throws Exception {

    super.doDeleteById(new Object[] {new Long(id)});
  }

  /**
   * Delete Datas
   *
   * @param queryBean
   * @throws Exception
   */
  public void delete(ProductUIListDAOQueryBean queryBean) throws Exception {

    super.doDeleteByQuery(queryBean);
  }

  public void delete(ProductUIList aProductUIList) throws Exception {

    delete(aProductUIList.getId());
  }

  /**
   * Update Data Selective
   *
   * @param aProductUIList
   * @throws Exception
   */
  public void update(ProductUIList aProductUIList) throws Exception {

    PropertyUtils.setProperty(
        aProductUIList,
        _DataObjectProperty.LastModifyTime,
        new java.sql.Timestamp(System.currentTimeMillis()));

    if (aProductUIList.getId() == 0) {
      throw new Exception("Can not update object data whith out primary key value");
    }

    super.doUpdate(aProductUIList);

    ProductUIList tempObj = findById(aProductUIList.getId());

    if (tempObj != null) {
      PropertyUtils.copyProperties(aProductUIList, tempObj);
    }
  }

  /**
   * Batch Update Datas
   *
   * @param aProductUILists[]
   * @throws Exception
   */
  public void batchUpdate(ProductUIList[] aProductUILists) throws Exception {

    super.doBatchUpdate(aProductUILists);
  }

  /**
   * Update Data By Condictions
   *
   * @param aProductUIList
   * @param aValueCriteria
   * @param aTransaction
   * @throws Exception
   */
  public void update(ProductUIList aProductUIList, ProductUIListDAOQueryBean aQueryBean)
      throws Exception {

    PropertyUtils.setProperty(
        aProductUIList,
        _DataObjectProperty.LastModifyTime,
        new java.sql.Timestamp(System.currentTimeMillis()));

    super.doUpdateByQuery(aProductUIList, aQueryBean);
  }

  /**
   * Update Data By Condictions
   *
   * @param aQueryBean
   * @throws Exception
   */
  public void update(ProductUIListDAOQueryBean aQueryBean) throws Exception {
    super.doUpdateByQuery(aQueryBean);
  }

  protected void checkNullValue(ProductUIList aProductUIList) throws Exception {

    if (aProductUIList.getCode() == null) {
      throw new Exception("The ProductUIList.code value is not allow NULL");
    }

    if (aProductUIList.getName() == null) {
      throw new Exception("The ProductUIList.name value is not allow NULL");
    }

    if (aProductUIList.getType() == null) {
      throw new Exception("The ProductUIList.type value is not allow NULL");
    }

    if (aProductUIList.getValueProperty() == null) {
      throw new Exception("The ProductUIList.valueProperty value is not allow NULL");
    }

    if (aProductUIList.getLabelProperty() == null) {
      throw new Exception("The ProductUIList.labelProperty value is not allow NULL");
    }

    if (aProductUIList.getLastModifyUser() == null) {
      throw new Exception("The ProductUIList.lastModifyUser value is not allow NULL");
    }

    if (aProductUIList.getLastModifyTime() == null) {
      throw new Exception("The ProductUIList.lastModifyTime value is not allow NULL");
    }

    if (aProductUIList.getStatus() == null) {
      throw new Exception("The ProductUIList.status value is not allow NULL");
    }

    if (aProductUIList.getRemarks() == null) {
      throw new Exception("The ProductUIList.remarks value is not allow NULL");
    }

    if (aProductUIList.getDomainCode() == null) {
      throw new Exception("The ProductUIList.domainCode value is not allow NULL");
    }

    if (aProductUIList.getDomainName() == null) {
      throw new Exception("The ProductUIList.domainName value is not allow NULL");
    }

    if (aProductUIList.getSearchProperty() == null) {
      throw new Exception("The ProductUIList.searchProperty value is not allow NULL");
    }
  }

  /**
   * Get Data By ID
   *
   * @param final long id * @return ${businessObject.name}
   * @throws Exception
   */
  public ProductUIList findById(final long id) throws Exception {

    ProductUIListDAOQueryBean queryBean = new ProductUIListDAOQueryBean();

    ProductUIListDAOQueryBean.Criteria criteria = queryBean.createCriteria();

    criteria.andIdEqualTo(id);

    // queryBean.setDistinct(true);

    ProductUIList[] ProductUILists = query(queryBean);

    if (ProductUILists.length == 0) {
      return null;
    } else {
      return ProductUILists[0];
    }
  }

  /**
   * Query Data
   *
   * @param queryBean
   * @return ProductUIList[]
   * @throws Exception
   */
  public ProductUIList[] query(ProductUIListDAOQueryBean queryBean) throws Exception {

    List result = super.doQuery(queryBean, new JdbcProductUIListRowMapper());

    return (ProductUIList[]) result.toArray(new ProductUIList[result.size()]);
  }

  /**
   * Query ${businessObject.name} Selective
   *
   * @param queryBean
   * @return Map[]
   * @model
   * @throws Exception
   */
  public Map<String, Object>[] querySelective(ProductUIListDAOQueryBean queryBean)
      throws Exception {

    if (queryBean.getSelectProperties().isEmpty()) {
      queryBean.addAllSelectProperties();
    }

    return super.doQuerySelective(queryBean);
  }

  /**
   * Query Data Count
   *
   * @param queryBean
   * @return int
   * @throws Exception
   */
  public int queryCount(ProductUIListDAOQueryBean queryBean) throws Exception {

    return super.doQueryCount(queryBean);
  }

  public void synchronize(ProductUIList[] aProductUILists, ProductUIListDAOQueryBean queryBean)
      throws Exception {
    daoHelper.synchronize(aProductUILists, queryBean);
  }

  public void synchronize(
      ProductUIList[] aProductUILists,
      ProductUIListDAOQueryBean queryBean,
      net.dao.IDataAccessInterface.ISynchronizeCallback<ProductUIList> callBack)
      throws Exception {
    daoHelper.synchronize(aProductUILists, queryBean, callBack);
  }

  public static class JdbcProductUIListRowMapper implements RowMapper<ProductUIList> {

    public ProductUIList mapRow(ResultSet resultSet, int arg1) throws SQLException {
      ProductUIList object = new ProductUIList();

      int columnIndex = 1;

      int __dataType;

      try {

        Object id = null;

        id = resultSet.getObject(columnIndex++);

        object.setIdNull(resultSet.getBoolean(columnIndex++));

        if (id != null) {

          setBeanValue(object, _DataObjectProperty.Id, id);
        }

        Object domainId = null;

        domainId = resultSet.getObject(columnIndex++);

        object.setDomainIdNull(resultSet.getBoolean(columnIndex++));

        if (domainId != null) {

          setBeanValue(object, _DataObjectProperty.DomainId, domainId);
        }

        Object code = null;

        code = resultSet.getObject(columnIndex++);

        object.setCodeNull(resultSet.getBoolean(columnIndex++));

        if (code != null) {

          setBeanValue(object, _DataObjectProperty.Code, code);
        }

        Object name = null;

        name = resultSet.getObject(columnIndex++);

        object.setNameNull(resultSet.getBoolean(columnIndex++));

        if (name != null) {

          setBeanValue(object, _DataObjectProperty.Name, name);
        }

        Object type = null;

        type = resultSet.getObject(columnIndex++);

        object.setTypeNull(resultSet.getBoolean(columnIndex++));

        if (type != null) {

          setBeanValue(object, _DataObjectProperty.Type, type);
        }

        Object valueProperty = null;

        valueProperty = resultSet.getObject(columnIndex++);

        object.setValuePropertyNull(resultSet.getBoolean(columnIndex++));

        if (valueProperty != null) {

          setBeanValue(object, _DataObjectProperty.ValueProperty, valueProperty);
        }

        Object labelProperty = null;

        labelProperty = resultSet.getObject(columnIndex++);

        object.setLabelPropertyNull(resultSet.getBoolean(columnIndex++));

        if (labelProperty != null) {

          setBeanValue(object, _DataObjectProperty.LabelProperty, labelProperty);
        }

        Object lastModifyUser = null;

        lastModifyUser = resultSet.getObject(columnIndex++);

        object.setLastModifyUserNull(resultSet.getBoolean(columnIndex++));

        if (lastModifyUser != null) {

          setBeanValue(object, _DataObjectProperty.LastModifyUser, lastModifyUser);
        }

        Object lastModifyTime = null;

        __dataType = resultSet.getMetaData().getColumnType(columnIndex);

        if (__dataType == java.sql.Types.DATE
            || __dataType == java.sql.Types.TIME
            || __dataType == java.sql.Types.TIMESTAMP) {
          lastModifyTime = resultSet.getTimestamp(columnIndex++);

        } else {
          lastModifyTime = resultSet.getObject(columnIndex++);
        }

        object.setLastModifyTimeNull(resultSet.getBoolean(columnIndex++));

        if (lastModifyTime != null) {

          setBeanValue(object, _DataObjectProperty.LastModifyTime, lastModifyTime);
        }

        Object status = null;

        status = resultSet.getObject(columnIndex++);

        object.setStatusNull(resultSet.getBoolean(columnIndex++));

        if (status != null) {

          setBeanValue(object, _DataObjectProperty.Status, status);
        }

        Object remarks = null;

        remarks = resultSet.getObject(columnIndex++);

        object.setRemarksNull(resultSet.getBoolean(columnIndex++));

        if (remarks != null) {

          setBeanValue(object, _DataObjectProperty.Remarks, remarks);
        }

        Object iconProperty = null;

        iconProperty = resultSet.getObject(columnIndex++);

        object.setIconPropertyNull(resultSet.getBoolean(columnIndex++));

        if (iconProperty != null) {

          setBeanValue(object, _DataObjectProperty.IconProperty, iconProperty);
        }

        Object script = null;

        script = resultSet.getObject(columnIndex++);

        object.setScriptNull(resultSet.getBoolean(columnIndex++));

        if (script != null) {

          setBeanValue(object, _DataObjectProperty.Script, script);
        }

        Object searchProperty = null;

        searchProperty = resultSet.getObject(columnIndex++);

        object.setSearchPropertyNull(resultSet.getBoolean(columnIndex++));

        if (searchProperty != null) {

          setBeanValue(object, _DataObjectProperty.SearchProperty, searchProperty);
        }

        Object domainCode = null;

        domainCode = resultSet.getObject(columnIndex++);

        object.setDomainCodeNull(resultSet.getBoolean(columnIndex++));

        if (domainCode != null) {

          setBeanValue(object, _DataObjectProperty.DomainCode, domainCode);
        }

        Object domainName = null;

        domainName = resultSet.getObject(columnIndex++);

        object.setDomainNameNull(resultSet.getBoolean(columnIndex++));

        if (domainName != null) {

          setBeanValue(object, _DataObjectProperty.DomainName, domainName);
        }

        return object;
      } catch (Exception e) {
        throw new SQLException(e.getMessage());
      }
    }
  }
}
